// src/api/auth/login.js
import {post} from '@/api/request'
import {useAuthStore} from '@/stores/auth'

const path = '/account/login'

export const loginByPassword = async (email, password) => {
    try {
        const res = await post(path + '/byPassword', {
            principal: email,
            credential: password
        })

        if (res.success) {
            const authStore = useAuthStore()
            authStore.setAuthData(res.data.lsToken, res.data.accountId)
        }
        return res

    } catch (error) {
        return {
            success: false,
            message: error.message || '登录失败'
        }
    }
}